/*
package com.sky.task;

import com.aliyun.oss.AliyunOssOperator;
import com.sky.constant.RubbishSetConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class RemoveRubbishPicTask {
    @Autowired
    private AliyunOssOperator aliyunOssOperator;
    //创建一个单线程的定时任务线程池
    ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();

    @PostConstruct//springbean生命周期的初始化方法
   public void init(){
        log.info("启动定时清理垃圾图片任务");
        scheduledExecutor.scheduleWithFixedDelay(()-> {
            log.info("开始清理垃圾图片");
            try {
                //TODO 删除垃圾图片
                //获取垃圾图片的集合
                Set<String> set = RubbishSetConstant.RUBBISH_SET;
                //遍历集合，删除垃圾图片
                for (String picName : set) {
                    log.info("删除垃圾图片：{}", picName);
                    aliyunOssOperator.delete(picName);
                }
                set.clear();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }, 0, 60, TimeUnit.SECONDS);
    }
}
*/
